/*
 *  $Id$

    Copyright (C) 2008  Nathaniel Waisbrot

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package termint.gui;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

/**
 * Class for static utility functions relating to GUI stuff
 * @author Nathaniel Waisbrot
 *
 */
public class GUIUtil {
	/**
	 * Mouse-clicks are given in coordinates relative to the receiving widget.  This function translates
	 * relative coordinates into absolute coordinates
	 * @param c the Control to which the points are relative
	 * @param p the relative coordinates
	 * @return absolute coordinates
	 */
	public static Point screenPointFromControlPoint(Control c, Point p) {
		Point loc = c.getLocation();
		int x = p.x + loc.x;
		int y = p.y + loc.y;
		Composite next = c.getParent();
		while (next != null) {
			loc = next.getLocation();
			x += loc.x;
			y += loc.y;
			next = next.getParent();
		}
		return new Point(x,y);
	}
	public static Point screenPointFromControlPoint(Control c, int x, int y) {
		return screenPointFromControlPoint(c, new Point(x,y));
	}
}
